//
//  BaseNavigationBarView.swift
//  AIPhotoProcess
//
//  Created by aw031 on 17/10/2025.
//

import UIKit
import SnapKit

enum BaseNavigationBarViewType {
    case onlyLeftAndRight
    case onlyTitle
    case leftAndTitle
    case rightAndTitle
    case all
}

class BaseNavigationBarView: UIView {

    var clickTagBlock : EventAndIndexBlock?
    
    var navigationBarType : BaseNavigationBarViewType = .onlyLeftAndRight
    
    var centerTitle : String? {
        didSet {
            centerBtn.setTitle(centerTitle, for: .normal)
        }
    }
    
    
    lazy var leftBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.tag = 1000
        btn.setCustomImage(KImage("setBlackBackArrowIcon"))
        btn.addTarget(self, action: #selector(clickUpdataAction), for: .touchUpInside)
        return btn
    }()
    
    lazy var centerBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.tag = 1001
        btn.titleLabel?.font = FontMedium(17)
        btn.setTitleColor(ColorBlack, for: .normal)
        btn.addTarget(self, action: #selector(clickUpdataAction), for: .touchUpInside)
        return btn
    }()
    
    
    lazy var rightBtn: UIButton = {
        let btn = UIButton(type: .custom)
        btn.tag = 1002
        btn.addTarget(self, action: #selector(clickUpdataAction), for: .touchUpInside)
        return btn
    }()
    
    
    
    init(frame: CGRect , type : BaseNavigationBarViewType = .onlyLeftAndRight) {
        super.init(frame: frame)
        navigationBarType = type

//        switch navigationBarType {
//        case .onlyLeftAndRight:
//            setUpdatasHomeUI()
//        case .onlyTitle:
//            setUpdatasOnlyTitleUI()
//        case .leftAndTitle:
//            setUpdataLeftAndTitleUI()
//        case .rightAndTitle:
//            setUpdataLeftAndTitleUI()
//            
//        case .all:
//            setUpdataAllUI()
//        }
            setUpdatasHomeUI()

    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUpdatasHomeUI() {
        
    
        if navigationBarType == .onlyLeftAndRight || navigationBarType == .leftAndTitle || navigationBarType == .all{
            addSubview(leftBtn)
    
            leftBtn.snp.makeConstraints { make in
                make.centerY.equalToSuperview().offset(KStatusBarHeight/2.0 + 2);
                make.leading.equalTo(15);
                make.height.equalTo(24);
                make.width.equalTo(12);
            }
        }
        
        
        if navigationBarType == .rightAndTitle || navigationBarType == .onlyLeftAndRight || navigationBarType == .all{
            addSubview(rightBtn)
            rightBtn.snp.makeConstraints { make in
                make.centerY.equalToSuperview().offset(KStatusBarHeight/2.0);
                make.width.height.equalTo(28);
                make.trailing.equalTo(-15);
            }
        }
        
       


        if navigationBarType != .onlyLeftAndRight  {
            addSubview(centerBtn)
            if navigationBarType == .onlyTitle  {
                centerBtn.snp.makeConstraints { make in
                    make.centerY.equalToSuperview().offset(KStatusBarHeight/2.0 + 2);
                    make.leading.equalToSuperview().offset(5);
                    make.trailing.equalToSuperview().offset(-5);
                    make.height.equalTo(44);
                }
            }else {
                centerBtn.snp.makeConstraints { make in
                    make.centerY.equalToSuperview().offset(KStatusBarHeight/2.0 + 2);
                    make.leading.equalTo(48);
                    make.trailing.equalTo(-48);
                    make.height.equalTo(44);
                }
            }
        }
        
        
        
    }
    
    
    
    @objc func clickUpdataAction(_ sender : UIButton) {
        
        if let tempBlock = clickTagBlock {
            let tag = sender.tag - 1000
            tempBlock(sender,tag)
        }
    }
    
 

}
